<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../css/scroll-bar.css">
    <link rel="stylesheet" href="../css/sub-page.css">
    <link rel="stylesheet" href="../css/font.css">
</head>

<body>
    <div class="ok-body">
        <!--面包屑导航区域-->
        <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>任务管理</cite></a>
                <a><cite>基础设置</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh"></i>
            </a>
        </div>

        <div class="layui-tab" lay-filter="nav">
            <ul class="layui-tab-title">
                <li lay-id="3">基础设置</li>
            </ul>
            <div class="layui-tab-content">

                <div class="layui-tab-item  layui-show">
                    <!--form表单-->
                    <form class="layui-form layui-form-pane" lay-filter="flowsetting">
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="taskname" placeholder="请输入任务名称" autocomplete="off" class="layui-input"
                                    lay-verify="required">
                            </div>
                        </div>
                        <!-- <div class="layui-form-item">
                            <label class="layui-form-label">任务描述</label>
                            <div class="layui-input-block">
                                <input type="text" name="description" placeholder="请输入任务描述" autocomplete="off" class="layui-input"
                                    lay-verify="required">
                            </div>
                        </div> -->
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务标签</label>
                            <div class="layui-input-block">
                                <input type="text" name="tasktags" placeholder="请输入任务标签" autocomplete="off" class="layui-input"
                                    lay-verify="required">
                            </div>
                        </div>


                        <div class="layui-inline">
                            <label class="layui-form-label">标注分类</label>
                            <div class="layui-input-inline">
                                <select name="actions" lay-verify="required" lay-search="">
                                    <option value="">直接选择或搜索选择</option>
                                    <option value="0">数据筛选</option>
                                    <option value="1">单分类</option>
                                    <option value="2">多分类</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">任务描述</label>
                            <!-- <div class="layui-input-block">
                                        <textarea placeholder="请输入备注" class="layui-textarea" name="exttags"></textarea>
                                    </div> -->
                            <div id="demo" name="description"></div>
                        </div>
                        <div class="layui-form-item" style="margin:10px;z-index: -100;">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <input class="layui-hide" id='id' value="">
    <!--js逻辑-->
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/laymd/marked.min.js"></script>
    <script>
        layui.config({
            base: '../lib/laymd/'
        }).use(['element', 'table', 'jquery', 'form', 'laydate', 'laymd'], function () {
            var element = layui.element;
            var $ = layui.jquery;
            var form = layui.form;
            var laydate = layui.laydate;
            var laymd = layui.laymd;

            //实例化编辑器,可以多个实例
            var md = laymd.init('demo', {});
            //内容改变事件
            md.on('change', function () {
                //这里借用marked.js解析效率比HyperDown快,用户可自行找解析器
                this.setPreview(marked(this.getText()));
            });

            //初始化数据预览
            md.do('change');
            //表单初始赋值
            form.val('flowsetting', {
                "taskname": '<%=data.taskname%>',
                "tasktags": '<%=data.tasktags%>',
                "actions": '<%=data.actions%>',
                "description": decodeURIComponent('<%- data.description%>')
            })
            md.setPreview(marked(decodeURIComponent('<%- data.description%>')));
            //监听提交
            form.on('submit(add)', function (data) {
                data.field.taskid = $('#id').val();
                //layer.alert(JSON.stringify(data.field));
                $.ajax({
                    url: '/task/update',
                    method: 'post',
                    data: data.field,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg('操作成功');
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        } else {
                            layer.msg('操作失败');
                        }
                    },
                    error: function (data) {}
                })
                return false;
            });
        })
    </script>
</body>

</html>